home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / csrc1.arc / GOTHIC.C < prev    next >
C/C++ Source or Header  |  1989-07-27  |  3KB  |  167 lines

  1.  
  2. /*
  3.  *        G o t h i c   P r i n t e r
  4.  *
  5.  */
  6.  
  7. /*)BUILD    $(PROGRAM)    = GOTHIC
  8.         $(FILES)    = { gothic.c gottab.c }
  9. */
  10.  
  11. /*
  12.  * Courtesy of RTW
  13.  *
  14.  * Compile with gottab.c
  15.  *
  16.  * Prints the arguments, if none, it prompts for an output file and
  17.  * reads stdin.
  18.  *
  19.  *    If the first argument is -h, the display is halved.
  20.  *
  21.  *    / in the text reverses the background
  22.  *
  23.  * The following characters are displayed:
  24.  *
  25.  *    #.(@!$);-,?:'"  A-Z  a-z  0-9
  26.  *
  27.  * All others become blanks.
  28.  *
  29.  */
  30. #include <stdio.h>
  31.  
  32. char        outbuf[133];
  33. char        line[133];
  34. int        background    = 0;        /* Background color    */
  35. int        half        = 0;        /* Set to halve display    */
  36.  
  37. main (argc, argv)
  38. int        argc;
  39. char        *argv[];
  40.  
  41. {
  42.     register int        i;
  43.  
  44.     if (argc > 1 && argv[1][0] == '-' && (argv[1][1] | 040) == 'h') {
  45.         argc--;
  46.         argv++;
  47.         half++;
  48.     }
  49.     if (argc <= 1) {
  50.         printf("Gothic output file <terminal>: ");
  51.         fflush(stdout);
  52.         if (fgetss(outbuf, sizeof outbuf, stdin) == NULL)
  53.             panic("No output file", NULL);
  54.         if (half == 0) {
  55.             printf("Half size (Yes/No) <N>: ");
  56.             fflush(stdout);
  57.             if (fgetss(line, sizeof line, stdin) == NULL)
  58.                 panic("Unexpected EOF", NULL);
  59.             if ((line[0] | 040) == 'y')
  60.                 half++;
  61.         }
  62.         if (outbuf[0] != 0) {
  63.             if (freopen(outbuf, "w", stdout) == NULL)
  64.                 panic("Can't open", outbuf);
  65.         }
  66.         while (fgetss(line, sizeof line, stdin) != NULL) {
  67.             dotext(line);
  68.         }
  69.     }
  70.     else {
  71.         for (i = 1; i < argc; i++) {
  72.             dotext(argv[i]);
  73.         }
  74.         puts("\f");
  75.     }
  76. }
  77.  
  78. dotext(text)
  79. char        *text;
  80. /*
  81.  * Convert text to gothic letters, write them to stdout
  82.  */
  83. {
  84.     register char    *tp;
  85.     register int    c;
  86.  
  87.     for (tp = text; (c = *tp++) != 0;) {
  88.         if (c == '/')
  89.             background = (background) ? 0 : 2;
  90.         else    gothic(c);
  91.     }
  92. }
  93.  
  94. gothic(character)
  95. int        character;
  96. /*
  97.  * Process the character
  98.  */
  99. {
  100.     char            *gp;
  101.     register char        *op;
  102.     register int        i;
  103.     register int        byte;
  104.     int            index;
  105.     extern char        *gottab[];
  106.     int            lhalf;        /* Line half flag    */
  107.     int            chalf;        /* Column half flag    */
  108.         
  109.     index = (background) ? -1 : 0;
  110.     lhalf = chalf = 0;
  111.     gp = gottab[character & 127];
  112.     op = outbuf;
  113.     for (;;) {
  114.         if ((i = (*gp++ & 0377)) >= 254) {
  115.             if (background) {
  116.                 while (op < &outbuf[132])
  117.                     *op++ = 'X';
  118.             }
  119.             *op = 0;
  120.             lhalf = ~lhalf;
  121.             chalf = 0;
  122.             if (half) {
  123.                 if (lhalf) {
  124.                     outbuf[132 / 2] = 0;
  125.                     puts(outbuf);
  126.                 }
  127.             }
  128.             else {
  129.                 puts(outbuf);
  130.             }
  131.             op = outbuf;
  132.             if (i == 255)
  133.                 break;
  134.         }
  135.         else {
  136.             byte = "O X "[background - (index = (-1 - index))];
  137.             while (--i >= 0) {
  138.                 if (half) {
  139.                     chalf = ~chalf;
  140.                     if (chalf) {
  141.                         *op++ = byte;
  142.                     }
  143.                 }
  144.                 else {
  145.                     *op++ = byte;
  146.                 }
  147.             }
  148.             if (op >= &outbuf[132])
  149.                 panic("big line", NULL);
  150.         }
  151.     }
  152. }
  153.  
  154. panic(s, arg)
  155. char        *s;
  156. char        *arg;
  157. /*
  158.  * Fatal error exit
  159.  */
  160. {
  161.     fprintf(stderr, "?Gothic-E-fatal error %s", s);
  162.     if (arg != NULL)
  163.         fprintf(stderr, ": \"%s\"", arg);
  164.     fprintf(stderr, "\n");
  165.     exit(1);
  166. }
  167.